package work;

public class User {

    public double openUser(BankSystem bankSystem, double openMen) {
        if (openMen - bankSystem.men < 0) {
            bankSystem.men = bankSystem.men - openMen;
            try {
                throw new Allexception("开户的金额为10 元，当前缴纳为" + openMen + "元，还需缴纳" + bankSystem.men + "元");
            } catch (Allexception e) {
                e.printStackTrace();
            }
            //bankSystem.setUseMoney(-openMen);
        } else {
            bankSystem.setMoney(openMen - bankSystem.men);
            bankSystem.setUseMoney(openMen - 10);
            System.out.println("开户成功,当前余额为：" + bankSystem.getMoney());
            bankSystem.men = 0;
            bankSystem.flag = true;
        }
        return bankSystem.men;
    }

    public void peo(BankSystem bankSystem, String admin, String pwd) {
        bankSystem.setUserName(admin);
        bankSystem.setPassword(pwd);
    }

    public void inputMoney(BankSystem banksystem, String admin, String pwd, double money) throws Exception {
        if (banksystem.getUserName().equals(admin) && banksystem.getPassword().equals(pwd)) {
            banksystem.setMoney(banksystem.getMoney() + money);
            System.out.println("存钱成功！当前余额为" + banksystem.getMoney());
            banksystem.num = 3;
        } else {
            banksystem.num--;
            try {
                throw new Allexception("账号密码不匹配！！！" + "剩余" + banksystem.num + "次机会");
            } catch (Allexception e) {
                e.printStackTrace();
            }
            if (banksystem.num == 0){
                try {
                    throw new Allexception("次数已用完,系统自动关闭");
                } catch (Allexception e) {
                    e.printStackTrace();
                }
                System.exit(0);
            }
        }
    }

    public void outputMoney(BankSystem banksystem, String admin, String pwd, double money) throws Exception {
        if (banksystem.getUserName().equals(admin) && banksystem.getPassword().equals(pwd)) {
            if ((banksystem.getMoney() - money) < 0) {
                try {
                    throw new Allexception("煞笔，你不配取那么多,当前余额为:" + banksystem.getMoney());
                } catch (Allexception e) {
                    e.printStackTrace();
                }
            } else {
                banksystem.setMoney(banksystem.getMoney() - money);
                System.out.println("取钱成功！当前余额为" + banksystem.getMoney());
                banksystem.num = 3;
            }
        } else {
            banksystem.num--;
            try {
                throw new Allexception("账号密码不匹配！！！" + "剩余" + banksystem.num + "次机会");
            } catch (Allexception e) {
                e.printStackTrace();
            }
            if (banksystem.num == 0){
                try {
                    throw new Allexception("次数已用完,系统自动关闭");
                } catch (Allexception e) {
                    e.printStackTrace();
                }
                System.exit(0);
            }
        }
    }
}
